package cn.cdutetc.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "RegisterServlet", value = "/RegisterServlet",loadOnStartup = 1,initParams = {@WebInitParam(name = "count",value = "1")})
public class RegisterServlet extends HttpServlet {
    int count;
    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("init1.......");
        super.init(config);
    }

    @Override
    public void init() throws ServletException {
        System.out.println("init2......");
        super.init();
        String c=getInitParameter("count");
        System.out.println(c);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        out.print(count++);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String username=request.getParameter("username");
        String password=request.getParameter("pwd");
        String[] hobbies=request.getParameterValues("hobby");
        //response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        out.println("用户名"+username);
        out.println("密码"+password);
        for (String hobby:hobbies)
        {
            out.println(hobby);
        }
        //重定向
        response.sendRedirect("/html/login.html");
    }
}
